package com.fxnotes.page;

import com.fxnotes.AppController;
import com.fxnotes.Resources;
import com.fxnotes.command.ShowPage;
import com.fxnotes.common.ui.ModuleController;
import com.fxnotes.common.ui.NavigationPathBuilder;
import com.fxnotes.page.presenter.PageViewPresenter;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;

public class PageModule extends ModuleController {

    private AppController appController;
    private PageViewPresenter pageViewPresenter;

    @Inject
    public PageModule(EventBus eventBus, PageViewPresenter pagePresenter) {
        super(Resources.MODULE_PAGE);
        this.pageViewPresenter = pagePresenter;
        
        addPresenter(pagePresenter);
        eventBus.register(this);
    }

    @Inject
    public void setAppController(AppController appController) {
        this.appController = appController;
    }
    
    @Subscribe
    public void onShowPage(ShowPage command) {
        appController.showPath(NavigationPathBuilder.create()
                .append(Resources.MODULE_PAGE)
                .append(Resources.PRESENTER_PAGE_VIEW)
                .build());        
       pageViewPresenter.loadPage(command.getBook(), command.getChapter(), command.getPage()); 
    }    
}
